package com.lineage.data.item_etcitem.shop;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_MPUpdate;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Up_hm2 extends ItemExecutor {
  private static final Log _log = LogFactory.getLog(Up_hm2.class);
  
  private int _value;
  
  private int _limit_count;
  
  public static ItemExecutor get() {
    return new Up_hm2();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    if (pc.get_other().get_addmp() >= this._value * this._limit_count) {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("已超过可用数量上限: " + this._limit_count + "个。"));
      return;
    } 
    pc.getInventory().removeItem(item, 1L);
    pc.get_other().set_addmp(pc.get_other().get_addmp() + this._value);
    pc.addMaxMp(this._value);
    pc.sendPackets((ServerBasePacket)new S_MPUpdate(pc));
    try {
      pc.save();
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  public void set_set(String[] set) {
    try {
      this._value = Integer.parseInt(set[1]);
    } catch (Exception exception) {}
    try {
      this._limit_count = Integer.parseInt(set[2]);
    } catch (Exception exception) {}
  }
}
